//
//  MainViewController.m
//  家校互通
//
//  Created by 姬鑫宇 on 15/5/11.
//  Copyright (c) 2015年 姬鑫宇. All rights reserved.
//
#define BUTTONWIDTH 44

#import "MainViewController.h"

#import "PublishMsgViewController.h"

#import "DSFScanQRCodeViewController.h"

#import "MenuView.h"

#import "ClassMemberViewController.h"

#import "ChooseMsgVisibleView.h"
@interface MainViewController ()<ChooseMsgVisibleViewDelegate>
{
    NSMutableArray *titleArray;
    NSMutableArray *imgArray ;
}
@end

@implementation MainViewController

-(void)viewWillAppear:(BOOL)animated{
    
    [self.navigationController setNavigationBarHidden:NO animated:NO];
    //加号
//    UIButton * button = [[UIButton alloc]initWithFrame:CGRectMake(0,0,BUTTONWIDTH,BUTTONWIDTH)];
//    button.tag = 7000;
////    [button setTitle:@"加号" forState:UIControlStateNormal];
////    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    [button setImage:[UIImage imageNamed:@"添加"] forState:UIControlStateNormal];
//    [button addTarget:self action:@selector(showNavigationButtonView:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(showNavigationButtonView:)];
    self.navigationItem.rightBarButtonItem = buttonItem;
    //XX班级
    self.title = [DSFUserInfo shareUserInstance].clazz_user.clazz.name;
    //星号

}
- (IBAction)changeUserState:(UIButton *)sender {
    
    NSArray *titleArrayList=[NSArray arrayWithObjects:@"班级(班主任)",@"班级(班主任)",@"班级(班主任)", nil];
    
    ChooseMsgVisibleView *chooseView=[[ChooseMsgVisibleView alloc]initWithFrame:CGRectMake((DSF_SCREENWIDTH-200)/2,(DSF_SCREENHEIGHT-(titleArrayList.count+1)*40)/2-44,  200, (titleArrayList.count+1)*40+10) withTitleArray:titleArrayList andHeaderTitle:@"身份切换"];
    chooseView.delegate=self;
    [chooseView presentViewFromVisibleView:[UIApplication sharedApplication].keyWindow];
}
- (void)chooseMsgVisibleViewWithContent:(NSString *)content
{
    NSLog(@"%@",content);
}
// 加号键
- (void)showNavigationButtonView:(id)sender{
    NSMutableArray *array = [[NSMutableArray alloc]init];
    
    if ([DSFUserInfo shareUserInstance].isTeachLogin) {
//        titleArray=[NSMutableArray arrayWithObjects:@"作业",@"表彰",@"通知",@"活动",@"聊天",@"扫一扫", nil];
//        imgArray=[NSMutableArray arrayWithObjects:@"作业1",@"表彰2",@"通知1",@"活动1",@"聊天1",@"扫一扫1", nil];
        titleArray=[NSMutableArray arrayWithObjects:@"作业",@"表彰",@"通知",@"活动",@"聊天",@"扫一扫", nil];
        imgArray=[NSMutableArray arrayWithObjects:@"作业1",@"表彰2",@"通知1",@"活动1",@"聊天1",@"扫一扫1", nil];
    }else{
        titleArray=[NSMutableArray arrayWithObjects:@"请假条",@"聊天",@"扫一扫", nil];
        imgArray=[NSMutableArray arrayWithObjects:@"请假条2",@"聊天1",@"扫一扫1", nil];
    }
    
    for (NSInteger i = 0; i <titleArray.count; i++) {
        NSString *string = [titleArray objectAtIndex:i];
        
        MenuItem *menuItem = [[MenuItem alloc] initWithTitle:string iconName:[imgArray objectAtIndex:i] index:i];
        [array addObject:menuItem];
    }
    
    MenuView *centerButton = [[MenuView alloc] initWithFrame:self.view.bounds items:array];
    __weak __typeof(self)weakSelf = self;
    centerButton.didSelectedItemCompletion = ^(MenuItem *selectedItem) {
        [weakSelf popMenuViewSelectIndex:selectedItem.index];
    };
//    [centerButton showMenu];
    [centerButton showMenuAtView:[UIApplication sharedApplication].keyWindow startPoint:CGPointMake(0, -100) endPoint:CGPointMake(0, -100)];
}

#pragma mark App JKPopMenuViewSelectDelegate
- (void)popMenuViewSelectIndex:(NSInteger)index
{
    NSString *titleString=[titleArray objectAtIndex:index];
    if ([titleString isEqualToString:@"作业"]) {
        //发布
        PublishMsgViewController *viewController=[self.storyboard instantiateViewControllerWithIdentifier:@"PublishMsgViewController"];
        viewController.title=@"作业发布";
        viewController.publishMsgStyle=PublishMsgStyleHomeWork;
        [self.navigationController pushViewController:viewController animated:YES];
    }else  if ([titleString isEqualToString:@"表彰"]) {
        //发布
        PublishMsgViewController *viewController=[self.storyboard instantiateViewControllerWithIdentifier:@"PublishMsgViewController"];
        viewController.title=@"表彰发布";
        viewController.publishMsgStyle=PublishMsgStylePraise;
        [self.navigationController pushViewController:viewController animated:YES];
    }else  if ([titleString isEqualToString:@"通知"]) {
        //发布
        PublishMsgViewController *viewController=[self.storyboard instantiateViewControllerWithIdentifier:@"PublishMsgViewController"];
        viewController.title=@"通知发布";
        viewController.publishMsgStyle=PublishMsgStyleNotice;
        [self.navigationController pushViewController:viewController animated:YES];
    }else  if ([titleString isEqualToString:@"活动"]) {
        //发布
        PublishMsgViewController *viewController=[self.storyboard instantiateViewControllerWithIdentifier:@"PublishMsgViewController"];
        viewController.title=@"活动发布";
        viewController.publishMsgStyle=PublishMsgStyleActivity;
        [self.navigationController pushViewController:viewController animated:YES];
    }else  if ([titleString isEqualToString:@"请假条"]) {
        //发布
        PublishMsgViewController *viewController=[self.storyboard instantiateViewControllerWithIdentifier:@"PublishMsgViewController"];
        viewController.title=@"请假条";
        viewController.publishMsgStyle=PublishMsgStyleAskLeave;
        [self.navigationController pushViewController:viewController animated:YES];
    }else  if ([titleString isEqualToString:@"聊天"]) {
        ClassMemberViewController *vc=[self.storyboard instantiateViewControllerWithIdentifier:@"ClassMemberViewController"];
        vc.title=@"班级成员";
       
        [self.navigationController pushViewController:vc animated:YES];
    }else  if ([titleString isEqualToString:@"扫一扫"]) {
        
        DSFScanQRCodeViewController *viewController=[[DSFScanQRCodeViewController alloc]init];
        viewController.title=@"扫一扫";
        [self.navigationController pushViewController:viewController animated:YES];
     
    }
 
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.mainView.tabItemNormalColor = [UIColor blackColor];
    self.mainView.tabItemSelectedColor = [UIColor redColor];
    self.mainView.shadowImage = [[UIImage imageNamed:@"red_line_and_shadow"]stretchableImageWithLeftCapWidth:44.0f topCapHeight:0.0f];
//    _mainView.tabItemNormalBackgroundImage=[UIImage imageNamed:@"red_line_and_shadow"];
//    _mainView.tabItemNormalBackgroundImage=[UIImage imageNamed:@"red_line_and_shadow"];
     self.mainView.sliderBtnWidth=DSF_SCREENWIDTH/3;
    self.mainView.slideSwitchViewDelegate = self;
    self.mainView.rigthSideButton = nil;
  
    self.blackVC = [self.storyboard  instantiateViewControllerWithIdentifier:@"BlackBoardViewController"];
    self.blackVC.title = @"     黑板报     ";
    
    self.newsVC = [self.storyboard  instantiateViewControllerWithIdentifier:@"NewsViewController"];
    self.newsVC.title = @"     消息     ";
    
    self.myVC = [self.storyboard  instantiateViewControllerWithIdentifier:@"MyViewController"];
    self.myVC.title = @"      我的      ";
    
    self.columnArray = [[NSMutableArray alloc] initWithCapacity:0];
    self.viewControllerArray = [[NSMutableArray alloc] initWithCapacity:0];
    
    [self.columnArray addObjectsFromArray:@[@"黑板报",@"消息",@"我的"]];
    [self.viewControllerArray addObject:self.blackVC];
    [self.viewControllerArray addObject:self.newsVC];
    [self.viewControllerArray addObject:self.myVC];

    [self.mainView buildUI];
  
    self.navigationItem.backBarButtonItem=[[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:NULL];
    NSLog(@"%@",self.navigationItem.backBarButtonItem);
    AppDelegate *_appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    _appDelegate.mainViewController=self;
}

#pragma mark - 滑动tab视图代理方法

- (NSUInteger)numberOfTab:(SUNSlideSwitchView *)view
{
    return [self.viewControllerArray count];
}

- (UIViewController *)slideSwitchView:(SUNSlideSwitchView *)view viewOfTab:(NSUInteger)number
{

    return  (UIViewController *)[self.viewControllerArray objectAtIndex:number];
}

- (void)slideSwitchView:(SUNSlideSwitchView *)view panLeftEdge:(UIPanGestureRecognizer *)panParam
{
//    SUNViewController *drawerController = (SUNViewController *)self.navigationController.mm_drawerController;
//    [drawerController panGestureCallback:panParam];
}

- (void)slideSwitchView:(SUNSlideSwitchView *)view didselectTab:(NSUInteger)number
{
//    SUNListViewController *vc = nil;
//    if (number == 0) {
//        vc = self.vc1;
//    } else if (number == 1) {
//        vc = self.vc2;
//    } else if (number == 2) {
//        vc = self.vc3;
//    } else if (number == 3) {
//        vc = self.vc4;
//    } else if (number == 4) {
//        vc = self.vc5;
//    } else if (number == 5) {
//        vc = self.vc6;
//    }
//    [vc viewDidCurrentView];
}

- (void)slideSwitchView:(SUNSlideSwitchView *)view panRightEdge:(UIPanGestureRecognizer*) panParam{

}


#pragma mark - 内存报警

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
